using System;   
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class RowDeletingEventPage : System.Web.UI.Page
{
    SqlDataSource sqlDataSource;
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
            FillRecruiterAccount(GridView1);
    }

    void FillRecruiterAccount(GridView gridView)
    {
        sqlDataSource = new SqlDataSource();
        sqlDataSource.ConnectionString =
        WebConfigurationManager.ConnectionStrings[
            "RecruitVietnamDbConnectionString"
            ].ConnectionString;
        sqlDataSource.SelectCommandType =
        SqlDataSourceCommandType.Text;
        sqlDataSource.SelectCommand = "select " +
        "RecruiterID,Email,CompanyName, "
        + "ContactName,Address,Activate from tblRCAccounts";
        gridView.DataSource = sqlDataSource;
        gridView.DataBind();

    }




    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {                
    
        if(Delete( GridView1.Rows[ e.RowIndex ].Cells[0].Text , GridView1 ))
            FillRecruiterAccount(GridView1);
            
             
    }
    bool Delete(string recruiterID, GridView gridView)
    {
        bool delete= false;
        sqlDataSource = new SqlDataSource();
        sqlDataSource.ConnectionString =
        WebConfigurationManager.ConnectionStrings[
            "RecruitVietnamDbConnectionString"
            ].ConnectionString;
        sqlDataSource.DeleteCommandType =
        SqlDataSourceCommandType.Text;
        sqlDataSource.DeleteCommand = 
        "Delete from tblRCAccounts where " +
        "RecruiterID=@RecruiterID";
        sqlDataSource.DeleteParameters.Add(
        "RecruiterID", recruiterID );
        delete=( sqlDataSource.Delete()>0); 
        return delete;       
    }


    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        FillRecruiterAccount(GridView1);
    }
}
